﻿<UserControl x:Class="MediaAssistant.Controls.MusicList.MusicListView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:Converters="clr-namespace:MediaAssistant.Converters"
             xmlns:Behavior="clr-namespace:MefBasic.Behaviors;assembly=MefBasic" 
             xmlns:Constants="clr-namespace:MediaAssistant.DAL.Constants;assembly=MediaAssistant.DAL"
             xmlns:cal="clr-namespace:Microsoft.Practices.Composite.Presentation.Regions;assembly=Microsoft.Practices.Composite.Presentation"
             xmlns:Constants1="clr-namespace:MediaAssistant.Constants">
    <UserControl.Resources>
        <Converters:ProbabilityToPercentageConverter x:Key="ProbabilityToPercentageConverter" />
        <Converters:PrepareMusicConverter x:Key="PrepareMusicConverter" />
    </UserControl.Resources>
    <DockPanel Margin="0,0,10,0">
        <Border DockPanel.Dock="Top" Height="35" Background="#ECECEC">
            <DockPanel>
                <ItemsControl DockPanel.Dock="Left" cal:RegionManager.RegionName="{x:Static Constants1:MediaAssistantRegionNames.MusicListBar}">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <DockPanel/>
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                </ItemsControl>
            </DockPanel>
        </Border>
        <Border DockPanel.Dock="Top">
            <DataGrid Name="Grid" HorizontalAlignment="Stretch" IsReadOnly="True"
         CanUserAddRows="False"
         CanUserDeleteRows="False"
         CanUserSortColumns="True"
         AutoGenerateColumns="False"
         AlternatingRowBackground="{StaticResource AlternatingRowBackground}"
         RowBackground="{StaticResource RowBackground}"
         HorizontalGridLinesBrush="{StaticResource GridLineBrush}"
         VerticalGridLinesBrush="{StaticResource GridLineBrush}"
         ItemsSource="{Binding DataSource.ResultMusics}"
         SelectionMode="Extended"
         Behavior:SelectionBehavior.SelectionChanged="{Binding SelectedMusicChangedCommand}"
         VirtualizingStackPanel.IsVirtualizing="True"
         VirtualizingStackPanel.VirtualizationMode="Standard"
         ScrollViewer.IsDeferredScrollingEnabled="True"
         EnableRowVirtualization="True"
         VerticalScrollBarVisibility="Auto"
         HorizontalScrollBarVisibility="Auto"
          MouseDoubleClick="HandleMouseDoubleClick"
          >
                <DataGrid.ContextMenu>
                    <ContextMenu>
                        <MenuItem Header="Play" Command="{Binding PlayCommand}"/>
                        <MenuItem Header="Add to Playlist" Command="{Binding AddToPlaylistCommand}"/>
                        <Separator/>
                        <MenuItem Header="Edit" Command="{Binding EditTagCommand}"/>
                        <MenuItem Header="Copy Files" Command="{Binding CopyFileCommand}"/>
                        <MenuItem Header="Remove From Library" Command="{Binding RemoveFromLibraryCommand}"/>
                        <Separator/>
                        <MenuItem Header="Show in Windows Explorer" Command="{Binding ShowInWindowsExplorerCommand}"/>
                    </ContextMenu>
                </DataGrid.ContextMenu>
                <DataGrid.Columns>
                    <DataGridTemplateColumn Header="" Width="45" IsReadOnly="True">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <DockPanel>
                                    <TextBlock Name="textBlock" DockPanel.Dock="Left" Text="{Binding Index}" TextAlignment="Right" Width="25"/>
                                    <ContentControl Name="Icon" DockPanel.Dock="Right" Content="{StaticResource NonPlayingMusicImage}" Margin="3,0,0,0" Width="15" Height="15"/>
                                </DockPanel>
                                <DataTemplate.Triggers>
                                    <DataTrigger Binding="{Binding Status}" Value="{x:Static Constants:MusicStatus.Playing}">
                                        <Setter Property="Content" Value="{StaticResource PlayingMusicImage}" TargetName="Icon"/>
                                        <Setter Property="FontWeight" Value="Bold" TargetName="textBlock"/>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Status}" Value="{x:Static Constants:MusicStatus.NowPlaying}">
                                        <Setter Property="Content" Value="{StaticResource NowPlayingMusicImage}" TargetName="Icon"/>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Status}" Value="{x:Static Constants:MusicStatus.NonPlaying}">
                                        <Setter Property="Content" Value="{StaticResource NonPlayingMusicImage}" TargetName="Icon"/>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Status}" Value="{x:Static Constants:MusicStatus.Failed}">
                                        <Setter Property="Content" Value="{StaticResource FailedToPlayMusicImage}" TargetName="Icon"/>
                                        <Setter Property="Foreground" Value="Red" TargetName="textBlock"/>
                                    </DataTrigger>
                                </DataTemplate.Triggers>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>

                    <DataGridTemplateColumn Header="File Name" Width="160" IsReadOnly="True">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Name="textBlock" Text="{Binding Path=FileName}" FontWeight="Normal"/>
                                <DataTemplate.Triggers>
                                    <DataTrigger Binding="{Binding Status}" Value="{x:Static Constants:MusicStatus.Playing}">
                                        <Setter Property="FontWeight" Value="Bold" TargetName="textBlock"/>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Status}" Value="{x:Static Constants:MusicStatus.Failed}">
                                        <Setter Property="Foreground" Value="Red" TargetName="textBlock"/>
                                    </DataTrigger>
                                </DataTemplate.Triggers>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>

                    <DataGridTemplateColumn Header="Title" Width="150">
                        <DataGridTemplateColumn.CellEditingTemplate>
                            <DataTemplate>
                                <TextBox Text="{Binding Title}"/>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellEditingTemplate>
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Name="textBlock" Text="{Binding Title}"/>
                                <DataTemplate.Triggers>
                                    <DataTrigger Binding="{Binding Status}" Value="{x:Static Constants:MusicStatus.Playing}">
                                        <Setter Property="FontWeight" Value="Bold" TargetName="textBlock"/>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Status}" Value="{x:Static Constants:MusicStatus.Failed}">
                                        <Setter Property="Foreground" Value="Red" TargetName="textBlock"/>
                                    </DataTrigger>
                                </DataTemplate.Triggers>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>

                    <DataGridTemplateColumn Header="Artist" Width="120">
                        <DataGridTemplateColumn.CellEditingTemplate>
                            <DataTemplate>
                                <TextBox Text="{Binding Artist}"/>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellEditingTemplate>
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Name="textBlock" Text="{Binding Artist}"/>
                                <DataTemplate.Triggers>
                                    <DataTrigger Binding="{Binding Status}" Value="{x:Static Constants:MusicStatus.Playing}">
                                        <Setter Property="FontWeight" Value="Bold" TargetName="textBlock"/>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Status}" Value="{x:Static Constants:MusicStatus.Failed}">
                                        <Setter Property="Foreground" Value="Red" TargetName="textBlock"/>
                                    </DataTrigger>
                                </DataTemplate.Triggers>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>

                    <DataGridTemplateColumn Header="Album" Width="120">
                        <DataGridTemplateColumn.CellEditingTemplate>
                            <DataTemplate>
                                <TextBox Text="{Binding Album}"/>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellEditingTemplate>
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Name="textBlock" Text="{Binding Album}"/>
                                <DataTemplate.Triggers>
                                    <DataTrigger Binding="{Binding Status}" Value="{x:Static Constants:MusicStatus.Playing}">
                                        <Setter Property="FontWeight" Value="Bold" TargetName="textBlock"/>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Status}" Value="{x:Static Constants:MusicStatus.Failed}">
                                        <Setter Property="Foreground" Value="Red" TargetName="textBlock"/>
                                    </DataTrigger>
                                </DataTemplate.Triggers>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>

                    <DataGridTemplateColumn Header="Genre" Width="100">
                        <DataGridTemplateColumn.CellEditingTemplate>
                            <DataTemplate>
                                <TextBox Text="{Binding Genre}"/>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellEditingTemplate>
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Name="textBlock" Text="{Binding Genre}"/>
                                <DataTemplate.Triggers>
                                    <DataTrigger Binding="{Binding Status}" Value="{x:Static Constants:MusicStatus.Playing}">
                                        <Setter Property="FontWeight" Value="Bold" TargetName="textBlock"/>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Status}" Value="{x:Static Constants:MusicStatus.Failed}">
                                        <Setter Property="Foreground" Value="Red" TargetName="textBlock"/>
                                    </DataTrigger>
                                </DataTemplate.Triggers>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>

                    <DataGridTemplateColumn Header="Composer" Width="120">
                        <DataGridTemplateColumn.CellEditingTemplate>
                            <DataTemplate>
                                <TextBox Text="{Binding Composer}"/>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellEditingTemplate>
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Name="textBlock" Text="{Binding Composer}"/>
                                <DataTemplate.Triggers>
                                    <DataTrigger Binding="{Binding Status}" Value="{x:Static Constants:MusicStatus.Playing}">
                                        <Setter Property="FontWeight" Value="Bold" TargetName="textBlock"/>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Status}" Value="{x:Static Constants:MusicStatus.Failed}">
                                        <Setter Property="Foreground" Value="Red" TargetName="textBlock"/>
                                    </DataTrigger>
                                </DataTemplate.Triggers>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>

                    <DataGridTemplateColumn Header="Size" Width="60" IsReadOnly="True">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Name="textBlock" Text="{Binding SizeText}" TextAlignment="Right"/>
                                <DataTemplate.Triggers>
                                    <DataTrigger Binding="{Binding Status}" Value="{x:Static Constants:MusicStatus.Playing}">
                                        <Setter Property="FontWeight" Value="Bold" TargetName="textBlock"/>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Status}" Value="{x:Static Constants:MusicStatus.Failed}">
                                        <Setter Property="Foreground" Value="Red" TargetName="textBlock"/>
                                    </DataTrigger>
                                </DataTemplate.Triggers>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>

                    <!--<DataGridTemplateColumn Header="Time" Width="50" IsReadOnly="True">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Name="textBlock" Text="{Binding TimeText}" TextAlignment="Right"/>
                                <DataTemplate.Triggers>
                                    <DataTrigger Binding="{Binding Status}" Value="{x:Static Constants:MusicStatus.Playing}">
                                        <Setter Property="FontWeight" Value="Bold" TargetName="textBlock"/>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Status}" Value="{x:Static Constants:MusicStatus.Failed}">
                                        <Setter Property="Foreground" Value="Red" TargetName="textBlock"/>
                                    </DataTrigger>
                                </DataTemplate.Triggers>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>-->
                    <DataGridTemplateColumn Header="Preferance" Width="80" IsReadOnly="True">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Name="textBlock" TextAlignment="Right" Text="{Binding Preferance}">
              <!--<TextBlock.Text>
                <MultiBinding Converter="{StaticResource PrepareMusicConverter}">
                  <Binding/>
                  <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}" Path="DataContext.DataSource" />
                  <Binding Path="Preferance"/>
                </MultiBinding>
              </TextBlock.Text>-->
                                </TextBlock>
                                <DataTemplate.Triggers>
                                    <DataTrigger Binding="{Binding Status}" Value="{x:Static Constants:MusicStatus.Playing}">
                                        <Setter Property="FontWeight" Value="Bold" TargetName="textBlock"/>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Status}" Value="{x:Static Constants:MusicStatus.Failed}">
                                        <Setter Property="Foreground" Value="Red" TargetName="textBlock"/>
                                    </DataTrigger>
                                </DataTemplate.Triggers>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>

                    <DataGridTemplateColumn Header="Probability" Width="80" IsReadOnly="True">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Name="textBlock" Text="{Binding Probability, Converter={StaticResource ProbabilityToPercentageConverter}}" TextAlignment="Right"/>
                                <DataTemplate.Triggers>
                                    <DataTrigger Binding="{Binding Status}" Value="{x:Static Constants:MusicStatus.Playing}">
                                        <Setter Property="FontWeight" Value="Bold" TargetName="textBlock"/>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Status}" Value="{x:Static Constants:MusicStatus.Failed}">
                                        <Setter Property="Foreground" Value="Red" TargetName="textBlock"/>
                                    </DataTrigger>
                                </DataTemplate.Triggers>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                </DataGrid.Columns>
            </DataGrid>
        </Border>
    </DockPanel>

</UserControl>
